import { ArticleDTO } from '@/bean/dto';
import {
  ArrayResponse,
  ObjectResponse,
  PageResponse,
  QueryNumberModel,
  QueryHotColumnModel,
  QueryPageModel,
  QuerySearchModel,
} from '@/bean/xhr';
import ajax from '.';
import { IDataType } from './type';

class ArticleService {
  Page = (params: QueryPageModel): Promise<PageResponse<ArticleDTO>> =>
    ajax.get('/article/page', { params });

  topRead = (params: QueryHotColumnModel): Promise<IDataType> =>
    ajax.get('/article/top_read', { params });

  PageByTag = (params: QuerySearchModel): Promise<PageResponse<ArticleDTO>> => {
    return ajax.get('/article/page_by_tag', { params });
  };
  pageByCategory = (
    params: QuerySearchModel
  ): Promise<PageResponse<ArticleDTO>> => {
    return ajax.get('/article/page_by_category', { params });
  };

  detail = (params: QueryNumberModel): Promise<ObjectResponse<ArticleDTO>> => {
    return ajax.get('/article/detail', { params });
  };
  public neighbors(
    params: QueryNumberModel
  ): Promise<ArrayResponse<ArticleDTO>> {
    return ajax.get('/article/neighbors', {
      params,
    });
  }
  public updateReadNum(id: number) {
    return ajax.put('/article/update_read_num', { id });
  }
}

export const articleService = new ArticleService();
